package fr.afcepf.atod.fee.dao.impl;

import java.util.List;

import fr.afcepf.atod.fee.beans.InterestRate;
import fr.afcepf.atod.fee.dao.IInterestRateDao;
import fr.afcepf.atod.util.dao.SimpleDao;

public class InterestRateDao extends SimpleDao implements IInterestRateDao {

	protected InterestRateDao() {
		super(InterestRate.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<InterestRate> getAllInterestRates() {
		return (List<InterestRate>) findAll();
	}

	@SuppressWarnings("unchecked")
	@Override
	public InterestRate getInterestRateById(long _idInterestRate) {
		String query = "from InterestRate f where f.range_num = ?";
		List<InterestRate> result = getHibernateTemplate().findByNamedQuery(
				query, _idInterestRate);
		return result.get(0);
	}

	@SuppressWarnings("unchecked")
	@Override
	public double getRangeNumByMonth(int _nb_month) {
		String query = "from InterestRate f where ? between f.nb_month_min and f.nb_month_max";
		List<InterestRate> result = getHibernateTemplate().findByNamedQuery(
				query, _nb_month);
		if (result != null && !result.isEmpty()) {
			return result.get(0).getMonthly_rate();
		} else
			return -1;
	}

}
